package com.edoomath.api.servcice.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.edoomath.api.dao.UserDao;
import com.edoomath.api.handler.SmsSender;
import com.edoomath.api.servcice.UserCourseCustomizeService;
import com.edoomath.entity.user.User;
import com.edoomath.entity.usercourse.UserCourseCustomize;

/**
 * 
 * @author mohanlan
 *
 */
@Service("userCourseCustomizeService")
public class UserCourseCustomizeServiceImpl implements UserCourseCustomizeService {

	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	@Autowired
	private SmsSender smsSender;
	
	@Dao
	private UserDao userDao;
	
	/*
	 * (non-Javadoc)
	 * @see com.edoomath.api.servcice.UserCourseCustomizeService#create(java.lang.String, com.edoomath.entity.usercourse.UserCourseCustomize)
	 */
	public void create(String unionid, UserCourseCustomize userCourseCustomize) {
		
		User user = userDao.loadUser(unionid);
		
		// 1. create 
		userCourseCustomize.bindUser(unionid);
		genericDaoSupport.save(userCourseCustomize.initliaze());
		
		// 2. send message to downpour
		smsSender.sendMessage("18918170415", "【陆老师小课堂】有新的用户[" + user.getNickname() + "]定制课程。定制类型为["+ userCourseCustomize.getType().getDescription() +"]请去系统查看。");
	}
	
}
